package com.py.pythink.third;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class JedisUtil {
    private static final String HOST="47.98.123.77";
    private static final Integer PORT=6380;
    private static final String PASS="123456";
    private static Jedis resource;
    static {
        JedisPool jedisPool = new JedisPool(HOST,PORT);
        resource = jedisPool.getResource();
        resource.auth(PASS);
    }
    //新增 分别是 键  值 以及键的有效期
    public static void addStr(String key,String val,long seconds){
        resource.select(10);
        resource.setex(key,seconds,val);
    }
    //查询
    public static String getStr(String key){
        resource.select(10);
        return resource.get(key);
    }
    //检验这个key是否存在 也就是手机号
    public static boolean checkKey(String key){
        resource.select(10);
        return resource.exists(key);
    }
    //返回剩余有效期
    public static long ttl(String key){
        resource.select(10);
        return resource.ttl(key);
    }
    //删除
    public static boolean delStr(String key){
        resource.select(10);
        return  resource.del(key)>0;
    }


//    //保存用户点赞数据的key
//    public static final String MAP_KEY_USER_LIKED = "MAP_USER_LIKED";
//    //保存用户被点赞数量的key
//    public static final String MAP_KEY_USER_LIKED_COUNT = "MAP_USER_LIKED_COUNT";
//
//    public static String getLikeKey(String likeUserId,String likedPostId){
//        StringBuffer stringBuffer = new StringBuffer();
//        stringBuffer.append(likeUserId);
//        stringBuffer.append("::");
//        stringBuffer.append(likedPostId);
//        return stringBuffer.toString();
//    }



}
